package com.encyclopedia.controller;


import com.encyclopedia.entity.Genus;
import com.encyclopedia.service.GenusService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/plant/genus")
public class GenusController {
    @Autowired
    private GenusService genusService;


    @GetMapping("/genusAll")
    public List<Genus> genusAll(Integer familyId) {

        return genusService.getGenusAllByFamilyId(familyId);
    }

    @GetMapping("/getGenusById")
    public Genus getGenus(@Param("genusId") Integer genusId) {

        return genusService.getGenusOneById(genusId);
    }

    @GetMapping("/getGenusByName")
    public List<Genus> getGenusByName(@Param("genusName") String genusName) {

        return genusService.getGenusByName(genusName);
    }


    @PostMapping("/addGenus")
    public Integer addGenus(Genus genus) {

        return genusService.addGenus(genus);
    }

    @PostMapping("/updateGenus")
    public Integer updateGenus(Genus genus) {

        return genusService.updateGenus(genus);
    }

    @DeleteMapping("/deleteGenus")
    public Integer deleteGenus(Integer genusId) {

        return genusService.deleteGenus(genusId);
    }


}
